package me.nibo.springboot.swagger.web;

import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import me.nibo.springboot.swagger.domain.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by nibo on 2016/6/8.
 */
@RestController
public class HelloController {

    private static final Logger LOGGER = LoggerFactory.getLogger(HelloController.class);


    @ApiOperation(value = "Say Hello，你好", notes = "这笔记有什么用？")
    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String index() {
        return "Hello World";
    }

    @ApiOperation(value = "获取信息", notes = "根据 id 获取基本信息")
    @ApiImplicitParam(name = "id", value = "用户ID", required = true,
            dataType = "long", paramType = "path")
    @RequestMapping(value = "/info/{id}", method = RequestMethod.GET)
    public Map<String, Object> info(@PathVariable Long id) {
        Map<String, Object> map = new HashMap<>();
        map.put("name", "张三");
        map.put("age", 20);
        map.put("id", id);
        return map;
    }

    @ApiOperation(value = "添加用户")
    @RequestMapping(value = "/user", method = RequestMethod.POST)
    public String postUser(@RequestBody User user) {
        LOGGER.info(user.toString());
        return "成功拉！Success";
    }
}
